package com.java.multipledatasource.registered;

/**
 * @author hu
 * @version 1.0
 * @date 2020/12/30 0030 下午 2:30
 * @description
 */
public enum RegisteredEnums {
   PHONE( (byte) 0, PhoneRegisteredEntity.class),
   USERNAME( (byte) 1, UserNameRegisteredEntity.class),
    ;

    private byte code;

    private Class aClass;

    RegisteredEnums(byte code, Class aClass) {
        this.code = code;
        this.aClass = aClass;
    }

    public byte getCode() {
        return code;
    }

    public void setCode(byte code) {
        this.code = code;
    }

    public Class getaClass() {
        return aClass;
    }

    public void setaClass(Class aClass) {
        this.aClass = aClass;
    }

    /**
     * code 校验
     * @param code
     * @return
     */
    public static  boolean checkCode(byte code) {
       for (RegisteredEnums item : RegisteredEnums.values()) {
           if (item.getCode() == code) {
               return  true;
           }
       }
       return  false;
   }


    public static  RegisteredEnums getInstance(byte code) {
        for (RegisteredEnums item : RegisteredEnums.values()) {
            if (item.getCode() == code) {
                return  item;
            }
        }
        return  null;
    }
}
